//
//  kwewf_pwdinput.m
//  kratos_framework_Example
//
//  Created by 7yao.top on 2018/10/29.
//  Copyright © 2018年 kratos_framework. All rights reserved.
//

#import "Kratos_pwdinput.h"
#import "k_const.h"
#import "UIView+kkk_viewExtionsion.h"


@interface Kratos_pwdinput()
@property (nonatomic,strong) UIButton *isSeleectDisPlay;

@end;



@implementation Kratos_pwdinput
- (instancetype)initWithpwdNumChangeBlock:(pwdNumChangeBlock)pwdNumChangeBlock
{
    self = [super init];
    if (self) {
        self.pwdNumChangeBlock = pwdNumChangeBlock;
    }
    return self;
}

- (UIButton *)Kra_isDisPlay
{
    if (_Kra_isDisPlay == nil) {
        _Kra_isDisPlay = [[UIButton alloc] init];
        _Kra_isDisPlay.backgroundColor = [UIColor yellowColor];
        [_Kra_isDisPlay addTarget:self action:@selector(Kratos_isDisPlayClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _Kra_isDisPlay;
}

- (void)Kratos_isDisPlayClick:(UIButton *)btn
{
    btn.selected = !self.isSeleectDisPlay.isSelected;
    self.Kra_textField.secureTextEntry = !btn.selected;
    
   
    
    self.isSeleectDisPlay = btn;
}

- (void)Kratos_setupUI
{
    [super Kratos_setupUI];
    [self Kratos_borderForColor:[UIColor lightTextColor] Kratos_borderWidth:0.5 Kratos_borderType:UIBorderSideTypeAll];
    self.Kra_textField = [[UITextField alloc] init];
    self.Kra_textField.placeholder = @"请输入密码";
    self.Kra_textField.secureTextEntry = true;
    self.Kra_textField.keyboardType =  UIKeyboardTypeNumberPad;
    self.Kra_textField.clearButtonMode = UITextFieldViewModeAlways;
    UIView * ff = [[UIView alloc]init];
    ff.frame = CGRectMake(0, 0, 10, 10);
    self.Kra_textField.leftViewMode = UITextFieldViewModeAlways;
    self.Kra_textField.leftView = ff;
    [self Kratos_borderForColor:[UIColor blackColor] Kratos_borderWidth:1 Kratos_borderType:UIBorderSideTypeAll];
    [self addSubview:self.Kra_textField];
    [self.Kra_textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.mas_equalTo(0);
        make.right.mas_equalTo(-40);
    }];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldChange:) name:UITextFieldTextDidChangeNotification object:self.Kra_textField];
    
    
    [self setupDisPlaybutton];

    
}
- (void)setupDisPlaybutton
{
    
    
    self.Kra_isDisPlay = [[UIButton alloc] init];
    self.Kra_isDisPlay.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self.Kra_isDisPlay setImage: [UIImage Kratos_setBundleImageName:@"ico_mimabukejian"] forState:UIControlStateNormal];
    self.Kra_isDisPlay.titleLabel.font = [UIFont systemFontOfSize:17];;
    [self.Kra_isDisPlay setImage: [UIImage Kratos_setBundleImageName:@"ico_mimakejian"] forState:UIControlStateSelected];
    [self.Kra_isDisPlay addTarget:self action:@selector(Kratos_isDisPlayClick:) forControlEvents:UIControlEventTouchUpInside];
    self.Kra_isDisPlay.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
    [self.Kra_isDisPlay setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self insertSubview:self.Kra_isDisPlay atIndex:0];
    [self.Kra_isDisPlay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self);
        make.bottom.mas_equalTo(self);
        make.right.mas_equalTo(self);
        make.width.mas_equalTo(self);
        
    }];
}

///记录是否为合法的手机号码
- (void)textFieldChange:(NSNotification *)note
{

    if (self.pwdNumChangeBlock != nil) {
        self.pwdNumChangeBlock (self.Kra_textField.text);
    }
}


- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}



@end
